package com.news.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.news.dao.News_CategoryDao;
import com.news.dao.News_DetailDao;
import com.news.entity.News_Category;
import com.news.entity.News_Detail;

/**
 * Servlet implementation class Inquire
 */
public class Inquire extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Inquire() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		int id =Integer.parseInt(request.getParameter("classify"));
		System.out.println("id：++"+id);
		String name=request.getParameter("name");
		System.out.println("名称：+dddddddddddddddd++"+name);
		request.removeAttribute("details");
		ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");
		News_DetailDao news_DetailDao =(News_DetailDao) context.getBean("news_DetailDao");
		List<News_Detail> details =news_DetailDao.getNews_DetailsByNameWithCategoryId(name, id);
		request.setAttribute("details", details);
		request.setAttribute("id", id);
		request.setAttribute("name", name);
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

}
